package smartcampus.scjava.controller.second;


import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import smartcampus.scjava.POJO.DO.Tuition;
import smartcampus.scjava.custom.ResultVO;
import smartcampus.scjava.service.TuitionFeeService;
import smartcampus.scjava.service.TuitionService;

@RestController
@RequestMapping("/tuition")
@ApiOperation("学费详情")
public class TuitionController {

    @Autowired
    TuitionService tuitionService;

    @Autowired
    TuitionFeeService tuitionFeeService;

    @GetMapping("/addTuition")
    @ApiOperation("新增一个学生的学费费用")
    public ResultVO<?> addTuitionDTO(Tuition tuition) {
        //新增一个学生的学费费用
        Boolean s = tuitionService.addTuition(tuition);
        if (s) {
            //然后执行金额统计该学生需缴纳的总金额
            tuitionFeeService.updateSumMoney();
            return ResultVO.success("新增金额成功,须缴纳学费已更新");
        } else return ResultVO.fail("新增失败");
    }

    @PostMapping("/updateisdelete")
    @ApiOperation("修改一个学生的消费详情")
    public ResultVO<?> updateisDelete(@RequestBody Tuition tuition) {
        System.out.println(tuition);
        //根据学号和学费类型确定是哪一条学费数据
        tuition.setIsDelete(1);
       Boolean a = tuitionService.updateisDelete(tuition);
       if (a){
           return ResultVO.success("已提交");
       }else {
           return  ResultVO.fail("修改失败");
       }
    }

}
